package com.awesome.core.support.security;

import org.springframework.security.crypto.codec.Utf8;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;
import org.springframework.util.DigestUtils;

/**
 * @Description
 * @Author Hongkai.Wang
 * @Date 2020/12/19 00:25
 */
@Component
public class AwesomePasswordEncoder implements PasswordEncoder {
    @Override
    public String encode(CharSequence rawPassword) {
        return DigestUtils.md5DigestAsHex(Utf8.encode(rawPassword));
    }

    @Override
    public boolean matches(CharSequence rawPassword, String encodedPassword) {
        return encodedPassword.equalsIgnoreCase(new String(Utf8.encode(rawPassword)));
        // todo 等到真实的用户表的时候，需要真是的比对
        // return encodedPassword.equals(this.encode(rawPassword));
    }
}
